package com.isnmp.nms.framework.discover;

import java.util.List;
import java.util.Vector;

import com.isnmp.common.base.MyException;
import com.isnmp.common.snmp.SNMPFactory;
import com.isnmp.common.snmp.SNMPSysConfig;
import com.isnmp.common.snmp.SNMPTarget;
import com.isnmp.nms.framework.discover.service.SearchBasicDeviceInfoService;
import com.isnmp.nms.framework.discover.service.SearchDeviceByIPRoaming;
import com.isnmp.nms.framework.discover.service.SearchNodeService;
import com.isnmp.nms.framework.discover.service.SearchResourceService;
import com.isnmp.nms.framework.discover.service.SearchRouterInfoService;
import com.isnmp.nms.framework.discover.service.SearchTopoRelationService;

public class DiscoverAPI {
    private static DiscoverAPI discoverServiceAPI;

    private DiscoverAPI() {
        try {
            SNMPFactory.init(1, null, 8088);
        } catch (Exception localException) {
            System.out.println("init snmpService erro:" + localException.getMessage());
            localException.printStackTrace();
        }
    }

    public static DiscoverAPI getDiscoverAPI() {
        if (discoverServiceAPI == null)
            discoverServiceAPI = new DiscoverAPI();
        return discoverServiceAPI;
    }

    /**
     * 根据网络号和一系列SNMP参数搜索设备
     * @param subNetIP
     * @param snmpTargetList
     * @param isUseICMP
     * @return
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public List<DeviceInfo> searchDevice(String subNetIP, List<SNMPTarget> snmpTargetList, boolean isUseICMP) {
        SNMPSysConfig.SnmpRetry = 2;
        try {
            Object localObject2 = new SearchNodeService().searchDevice(subNetIP, snmpTargetList, isUseICMP);
            return (List<DeviceInfo>) localObject2;
        } catch (Exception localException) {
            Object localObject2 = new Vector();
            return (List<DeviceInfo>) localObject2;
        } finally {
            SNMPSysConfig.SnmpRetry = 0;
        }
    }

    /**
     * 通过多个网络号和一系列SNMP参数（端口号、读共同体），搜索设备 
     * @param paramList
     * @param paramList1
     * @param paramBoolean
     * @return
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public List<DeviceInfo> searchDeviceByNetList(List<String> paramList, List<SNMPTarget> paramList1, boolean paramBoolean) {
        SNMPSysConfig.SnmpRetry = 2;
        try {
            Object localObject2 = new SearchNodeService().searchDeviceByNetList(paramList, paramList1, paramBoolean);
            return (List<DeviceInfo>) localObject2;
        } catch (Exception localException) {
            Object localObject2 = new Vector();
            return (List<DeviceInfo>) localObject2;
        } finally {
            SNMPSysConfig.SnmpRetry = 0;
        }
    }

    /**
     * 通过IP范围，和一系列SNMP参数（端口号、读共同体），搜索设备 
     * @param paramString1
     * @param paramString2
     * @param paramList
     * @param paramBoolean
     * @return
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public List<DeviceInfo> searchDevice(String startIP, String endIP, List snmpTargetList, boolean isUseICMP) {
        SNMPSysConfig.SnmpRetry = 2;
        try {
            Object localObject2 = new SearchNodeService().searchDevice(startIP, endIP, snmpTargetList, isUseICMP);
            return (List<DeviceInfo>) localObject2;
        } catch (Exception localException) {
            Object localObject2 = new Vector();
            return (List<DeviceInfo>) localObject2;
        } finally {
            SNMPSysConfig.SnmpRetry = 0;
        }
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public List<DeviceInfo> searchDeviceByIPList(List<String> paramList, List<SNMPTarget> paramList1, boolean paramBoolean) {
        SNMPSysConfig.SnmpRetry = 2;
        try {
            Object localObject2 = new SearchNodeService().searchDeviceByIPList(paramList, paramList1, paramBoolean);
            return (List<DeviceInfo>) localObject2;
        } catch (Exception localException) {
            Object localObject2 = new Vector();
            return (List<DeviceInfo>) localObject2;
        } finally {
            SNMPSysConfig.SnmpRetry = 0;
        }
    }

    /**
     * 从一个或多个已知的网络，按漫游深度和漫游广度，漫游搜索到其他设备 
     * @param paramList
     * @param paramList1
     * @param paramBoolean
     * @param paramInt1
     * @param paramInt2
     * @return
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public List<DeviceInfo> searchDeviceByIPRoaming(List<String> paramList, List<SNMPTarget> paramList1, boolean paramBoolean, int paramInt1, int paramInt2) {
        SNMPSysConfig.SnmpRetry = 2;
        try {
            Object localObject2 = new SearchDeviceByIPRoaming().searchDeviceByIPRoaming(paramList, paramList1, paramBoolean, paramInt1, paramInt2);
            return (List<DeviceInfo>) localObject2;
        } catch (Exception localException) {
            Object localObject2 = new Vector();
            return (List<DeviceInfo>) localObject2;
        } finally {
            SNMPSysConfig.SnmpRetry = 0;
        }
    }

    /**
     * 从路由器上搜索设备 
     * @param paramString
     * @param paramList
     * @param paramBoolean
     * @return
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public List<DeviceInfo> searchDeviceByRouterNet(String paramString, List<SNMPTarget> paramList, boolean paramBoolean) {
        SNMPSysConfig.SnmpRetry = 2;
        try {
            Object localObject2 = new SearchRouterInfoService().searchDeviceByRouterNet(paramString, paramList, paramBoolean);
            return (List<DeviceInfo>) localObject2;
        } catch (Exception localException) {
            Object localObject2 = new Vector();
            return (List<DeviceInfo>) localObject2;
        } finally {
            SNMPSysConfig.SnmpRetry = 0;
        }
    }

    public DeviceInfo getDeviceBasicInfo(String paramString, List<SNMPTarget> paramList, boolean paramBoolean) {
        try {
            return new SearchBasicDeviceInfoService().getDeviceBasicInfo(paramString, paramList, paramBoolean);
        } catch (Exception localException) {
        }
        return null;
    }

    /**
     * 获取设备的资源信息
     * @param paramDeviceInfo
     * @return
     * @throws MyException
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public List<ResourceInfo> searchDeviceResource(DeviceInfo paramDeviceInfo) throws MyException {
        SNMPSysConfig.SnmpRetry = 1;
        try {
            Object localObject2 = new SearchResourceService().searchDeviceResource(paramDeviceInfo);
            return (List<ResourceInfo>) localObject2;
        } catch (Exception localException) {
            Object localObject2 = new Vector();
            return (List<ResourceInfo>) localObject2;
        } finally {
            SNMPSysConfig.SnmpRetry = 0;
        }
    }

    /**
     * 发现任意网络设备之间的连接关系 
     * @param paramList
     * @return
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public List<LinkInfo> searchLinkInfo(List<DeviceInfo> paramList) {
        SNMPSysConfig.SnmpRetry = 2;
        Object localObject = new Vector();
        try {
            localObject = new SearchTopoRelationService().createAllLinks(paramList);
        } catch (Exception localException) {
            localException.printStackTrace();
        }
        SNMPSysConfig.SnmpRetry = 0;
        return (List<LinkInfo>) localObject;
    }
}